package com.back.business;

import java.util.List;

import org.apache.log4j.Logger;

import com.base.dao.BaseDao;
import com.base.dao.IBaseDao;
import com.domain.UserTable;

public class UserTableServiceImpl implements IUserTableService {
	private IBaseDao<UserTable, Long> dao = new BaseDao<UserTable, Long>(
			UserTable.class);
	private static final Logger LOGGER = Logger
			.getLogger(UserTableServiceImpl.class);

	/**
	 * 为true登陆成功，为false登入失败
	 */
	public boolean login(UserTable userTable) {
		try{
	    String  str="SELECT * FROM  usertable  WHERE  loginName=? AND  PASSWORD =?";
	     List list=  dao.findList(str, new Object[]{userTable.getLoginName(),userTable.getPassword()});
	     if(list!=null  && !list.isEmpty())
	     {
	    	 return  true;
	     }
		}catch (Exception e) {
			LOGGER.error("查询出错", e);
			return false;
		}
		return false;
	}
	
	/**
	 * @author lixiaomou
	 * @param id 用户id
	 * @param newPw 新密码
	 * @return boolean
	 */
	public boolean modifyPwById(Long id,String newPw) {
		String str = "UPDATE usertable t SET t.password =? WHERE  t.id =? "; 
		
		try{
			dao.update(str,new Object[]{newPw,id});
		   return true;	
		}catch(Exception e){
			LOGGER.error("修改密码出错", e);
			return false;
		}
	}

}
